package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CollectionMemberInfoBean;
import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.service.CollectionMemberInfoCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmember.Member;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
/**
*采集会员信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CollectionMemberInfo{
	private static CollectionMemberInfoBean collectionmemberinfoBean;
	private static CollectionMemberInfoCall collectionmemberinfoCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("采集会员信息");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		collectionmemberinfoBean=new CollectionMemberInfoBean();
		collectionmemberinfoCall=new CollectionMemberInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(collectionmemberinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verify(CollectionMemberInfoBean collectionmemberinfoBean2) throws InterruptedException {
		GodMemberWapper GodMemberWapper=new GodMemberWapper();
		Member mem = GodMemberWapper.selectMemberByUserId(collectionmemberinfoBean2.getUserId(),collectionmemberinfoBean2.getShopId()).get(0);
		Logger.debug("mem:"+FormatUtil.beanToGSONString(mem));
		Logger.verifyEquals(collectionmemberinfoBean2.getRealName(), mem.getRealName(), "验证getRealName");
		Logger.verifyEquals(collectionmemberinfoBean2.getSex(), mem.getSex(), "验证getSex");
		Logger.verifyEquals(collectionmemberinfoBean2.getWechatName(), mem.getWechatName(), "验证getWechatName");
		Logger.verifyNotNull(mem.getUpdateTime(), "验证UpdateTime");
		Logger.verifyNotNull(mem.getCreateTime(), "验证CreateTime");
		Logger.verifyNotNull(mem.getAccessTime(), "验证AccessTime");
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CollectionMemberInfo_001() {
		Logger.start(true,"采集会员信息成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			collectionmemberinfoBean.setUserId(userId);
			collectionmemberinfoBean.setShopId(shopid);
			collectionmemberinfoBean.setRealName("rn");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setWechatName("wcname");
			collectionmemberinfoCall.setData(collectionmemberinfoBean);
			collectionmemberinfoCall.callService();			
			Logger.verifyEquals("200", collectionmemberinfoCall.getString("code"), "验证code");
			Logger.verifyEquals("true", collectionmemberinfoCall.getJsonObject().get("data").getAsJsonObject().get("success").toString(), "验证data");
			verify(collectionmemberinfoBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CollectionMemberInfo_002() {
		Logger.start(true,"不输入memberid失败");
		try {
//			collectionmemberinfoBean.setMemberId(memid);
			collectionmemberinfoBean.setShopId(shopid);
			collectionmemberinfoBean.setRealName("rn");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setWechatName("wcname");
			collectionmemberinfoCall.setData(collectionmemberinfoBean);
			collectionmemberinfoCall.callService();			
			Logger.verifyEquals("400", collectionmemberinfoCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CollectionMemberInfo_003() {
		Logger.start(true,"不输入shopid失败");
		try {
			collectionmemberinfoBean.setUserId(1);
//			collectionmemberinfoBean.setShopId(shopid);
			collectionmemberinfoBean.setRealName("rn");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setWechatName("wcname");
			collectionmemberinfoCall.setData(collectionmemberinfoBean);
			collectionmemberinfoCall.callService();			
			Logger.verifyEquals("400", collectionmemberinfoCall.getString("code"), "验证code");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CollectionMemberInfo_004() {
		Logger.start(true,"不输入realName成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			collectionmemberinfoBean.setUserId(userId);
			collectionmemberinfoBean.setShopId(shopid);
//			collectionmemberinfoBean.setRealName("rn");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setWechatName("wcname");
			collectionmemberinfoCall.setData(collectionmemberinfoBean);
			collectionmemberinfoCall.callService();			
			Logger.verifyEquals("200", collectionmemberinfoCall.getString("code"), "验证code");
			Logger.verifyEquals("true", collectionmemberinfoCall.getJsonObject().get("data").getAsJsonObject().get("success").toString(), "验证data");
			verify(collectionmemberinfoBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CollectionMemberInfo_005() {
		Logger.start(true,"不输入sex成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			collectionmemberinfoBean.setUserId(userId);
			collectionmemberinfoBean.setShopId(shopid);
			collectionmemberinfoBean.setRealName("rn");
//			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setWechatName("wcname");
			collectionmemberinfoCall.setData(collectionmemberinfoBean);
			collectionmemberinfoCall.callService();			
			Logger.verifyEquals("200", collectionmemberinfoCall.getString("code"), "验证code");
			Logger.verifyEquals("true", collectionmemberinfoCall.getJsonObject().get("data").getAsJsonObject().get("success").toString(), "验证data");
			verify(collectionmemberinfoBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CollectionMemberInfo_006() {
		Logger.start(true,"不输入wechatName成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			collectionmemberinfoBean.setUserId(userId);
			collectionmemberinfoBean.setShopId(shopid);
			collectionmemberinfoBean.setRealName("rn");
			collectionmemberinfoBean.setSex("男");
//			collectionmemberinfoBean.setWechatName("wcname");
			collectionmemberinfoCall.setData(collectionmemberinfoBean);
			collectionmemberinfoCall.callService();			
			Logger.verifyEquals("200", collectionmemberinfoCall.getString("code"), "验证code");
			Logger.verifyEquals("true", collectionmemberinfoCall.getJsonObject().get("data").getAsJsonObject().get("success").toString(), "验证data");
			verify(collectionmemberinfoBean);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CollectionMemberInfo_007() {
		Logger.start(true,"memberid和shopid不匹配失败");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			collectionmemberinfoBean.setUserId(userId);
			collectionmemberinfoBean.setShopId(shopid+1);
			collectionmemberinfoBean.setRealName("rn");
			collectionmemberinfoBean.setSex("男");
			collectionmemberinfoBean.setWechatName("wcname");
			collectionmemberinfoCall.setData(collectionmemberinfoBean);
			collectionmemberinfoCall.callService();			
			Logger.verifyEquals("200", collectionmemberinfoCall.getString("code"), "验证code");
			Logger.verifyEquals("false", collectionmemberinfoCall.getJsonObject().get("data").getAsJsonObject().get("success").toString(), "验证data");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}